import { defineStore } from 'pinia';
import { getInputOption } from 'src/services/repairService';
import { threadId } from 'worker_threads';

export const useInputOption = defineStore('inputOptionStore', {
  state: () => ({
    data:{
      system:[],
      lv1:[],
      lv2:[],
      lv3:[],
      lv4:[],
      lv5:[],
      lv6:[],
      equipmentClass:[] as string[],
      workgroup:[]as string[],
    },
    filterClass: [
      {class:'EMUX-ATCCUB',lv1:'M Train',lv2:'ATC',lv3:'T-ATC',lv4:'SACEM Cubicle',lv5:''},
      {class:'EMUX-CAT010A',lv1:'M Train',lv2:'ATC',lv3:'T-ATC',lv4:'CAT010A',lv5:''},
      {class:'EMUX-CAT010B',lv1:'M Train',lv2:'ATC',lv3:'T-ATC',lv4:'CAT010B',lv5:''},
      {class:'EMUX-PREBOARD',lv1:'M Train',lv2:'ATC',lv3:'T-ATC',lv4:'PRE010',lv5:''},
      {class:'EMUX-VENTRACK-UP',lv1:'M Train',lv2:'ATC',lv3:'T-ATC',lv4:'Ventilation Rack (Up)',lv5:''},
      {class:'EMUX-VENTRACK-LWR',lv1:'M Train',lv2:'ATC',lv3:'T-ATC',lv4:'Ventilation Rack (Lower)',lv5:''},
      {class:'EMUX-PAV001',lv1:'M Train',lv2:'ATC',lv3:'T-ATC',lv4:'PAV001 (496207016)',lv5:''},
      {class:'EMUX-SACEM-RCANT',lv1:'M Train',lv2:'ATC',lv3:'T-ATC',lv4:'RC Antenna (M-Train/C-Train)',lv5:''},
      {class:'EMUX-CT',lv1:'M Train',lv2:'ATC',lv3:'T-ATC',lv4:'CT Sensor (M-Train)',lv5:''},
      {class:'EMUX-ODOMETER',lv1:'M Train',lv2:'ATC',lv3:'T-ATC',lv4:'Odometer (M-Train)',lv5:''},
      {class:'EMUX-TAGR',lv1:'M TrainURL C Train',lv2:'ATC',lv3:'T-ATC',lv4:'Tachogenerator (M-Train)',lv5:''},
      {class:'EMUYC-ATCCUB',lv1:'URL C Train',lv2:'ATC',lv3:'T-ATC',lv4:'SACEM Cubicle',lv5:''},
      {class:'EMUYC-CAT010A',lv1:'URL C Train',lv2:'ATC',lv3:'T-ATC',lv4:'CAT010A',lv5:''},
      {class:'EMUYC-CAT010B',lv1:'URL C Train',lv2:'ATC',lv3:'T-ATC',lv4:'CAT010B',lv5:''},
      {class:'EMUYC-PREBOARD',lv1:'URL C Train',lv2:'ATC',lv3:'T-ATC',lv4:'PRE010',lv5:''},
      {class:'EMUYC-PCE010B',lv1:'URL C Train',lv2:'ATC',lv3:'T-ATC',lv4:'PCE010B (496210384)',lv5:''},
      {class:'EMUYC-PAV001',lv1:'URL C Train',lv2:'ATC',lv3:'T-ATC',lv4:'PAV001 (496207016)',lv5:''},
      {class:'EMUYC-SACEM-RCANT',lv1:'URL C Train',lv2:'ATC',lv3:'T-ATC',lv4:'RC Antenna (M-Train/C-Train)',lv5:''},
      {class:'EMUYC-SACEM-CT',lv1:'URL C Train',lv2:'ATC',lv3:'T-ATC',lv4:'CT Sensor (C-Train)',lv5:''},
      {class:'EMUYC-ODOMETER',lv1:'URL C Train',lv2:'ATC',lv3:'T-ATC',lv4:'Odometer (C-Train)',lv5:''},
      {class:'EMUYC-TAGR',lv1:'URL C Train',lv2:'ATC',lv3:'T-ATC',lv4:'Tachogenerator (C-Train)',lv5:''},
      {class:'EMUYC-PCE010',lv1:'M Train',lv2:'ATC',lv3:'T-ATC',lv4:'PCE010 (496207014)',lv5:''},
    ] as {class:string,lv1:string,lv2:string,lv3:string,lv4:string,lv5:string}[]
  }),
  getters: {
  },
  actions: {
    async init(){
      const res = await getInputOption()
      console.log(res.data);
      this.data = res.data
      this.data = {...this.data, 
        equipmentClass:['EMUX-ATCCUB','EMUX-CAT010A','EMUX-CAT010B','EMUX-PREBOARD','EMUX-VENTRACK-UP','EMUX-VENTRACK-LWR','EMUX-PAV001','EMUX-SACEM-RCANT','EMUX-CT','EMUX-ODOMETER','EMUX-TAGR','EMUYC-ATCCUB','EMUYC-CAT010A','EMUYC-CAT010B','EMUYC-PREBOARD','EMUYC-PCE010B','EMUYC-PAV001','EMUYC-SACEM-RCANT','EMUYC-SACEM-CT','EMUYC-ODOMETER','EMUYC-TAGR','EMUYC-PCE010'].sort((a,b)=>{return a.localeCompare(b)}) as string[],
        workgroup:['A','B','C','D','E','F','G','H','CEWS','FIT']
      }
    },
    mapping(equipmentClass:string){
      const selected = this.filterClass.filter((item)=>{
        return item.class == equipmentClass
      })
      return selected[0]
    }
  },
});
